package com.example.user.util;

import java.util.Base64;

public class MainTest {
    public static void main(String[] args) {
        //元数据
        String data = "15226971825";
        //秘钥
        String key = "Qxq3fRvNkSyYzRdLFdR7Dg==";
        String dataEncrypt = null;
        try{
            byte[] keyByte = Base64.getDecoder().decode(key);
            byte[] cipherText = SM4Util.encrypt_ECB_Padding(keyByte, data.getBytes());
            dataEncrypt= Base64.getEncoder().encodeToString(cipherText);
            System.out.println(dataEncrypt);
        }catch(Exception e){
            e.printStackTrace();
        }
        //解密
        String jiemi = dataEncrypt;
        try {
            byte[] jiemiInput = Base64.getDecoder().decode(jiemi);
            byte[] keyByte = Base64.getDecoder().decode(key);
            byte[] decryptedData = SM4Util.decrypt_ECB_Padding(keyByte, jiemiInput);
            String jm = new String(decryptedData);
            System.out.println(jm);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
